package org.rayson.server.rpc;

import org.rayson.api.Protocol;
import org.rayson.api.server.FilterChain;
import org.rayson.api.server.ServerRequest;
import org.rayson.api.server.ServerResponse;
import org.rayson.api.server.ServiceFilter;
import org.rayson.api.server.exception.ServiceException;

public class DefaultFilterChain implements FilterChain {
	private final FilterChain next;
	private final Protocol service;
	private final ServiceFilter filter;

	public DefaultFilterChain(final Protocol service,
			final ServiceFilter filter, final FilterChain next) {
		this.service = service;
		this.filter = filter;
		this.next = next;
	}

	/**
	 * @return the filter
	 */
	protected ServiceFilter getFilter() {
		return filter;
	}

	protected FilterChain getNext() {
		return this.next;
	}

	protected Protocol getService() {
		return this.service;
	}

	@Override
	public void invoke(final ServerRequest request,
			final ServerResponse response) throws ServiceException {
		this.filter.invoke(request, response, next);
	}

}